home *** CD-ROM | disk | FTP | other *** search
/ UpTime Volume 2 #7 / utv2n7s1.d64 / file reader (.txt) < prev    next >
Encoding:
Commodore BASIC  |  1988-01-01  |  6.6 KB  |  208 lines

  1. 10 rem (c) 1988 uptime magazine
  2. 20 rem (c) 1988 softdisk publishing
  3. 30 :
  4. 40 rem author: noel nyman
  5. 50 :
  6. 60 rem ****************************
  7. 70 rem   initialize variables
  8. 80 rem ****************************
  9. 90 :
  10. 100 case=peek(53272) and 14: rem '4' if upper/graphics, '6' if lower/upper
  11. 110 if case=4 then print chr$(14): rem shift to lower/upper
  12. 120 r=0: rem flag for relative file reading
  13. 130 s=0: rem flag for sequential file reading
  14. 140 p=0: rem flag for program files
  15. 150 dim x, x$: rem global counter and misc input
  16. 160 dim f$: rem file name
  17. 170 dim er, er$: rem used for disk error messages
  18. 180 dim a$, b$, ad: rem used by 'prg' option
  19. 190 :
  20. 200 rem ****************************
  21. 210 rem       main program
  22. 220 rem ****************************
  23. 230 :
  24. 240 print "[147]" tab(13) " [198][201][204][197] [210][197][193][196][197][210] "
  25. 250 print "    written for [211]oftdisk [208]ublishing
  26. 260 [153] [163]13) "by (NULL)oel (NULL)yman
  27. 270 :
  28. 280 rem --- get file name in fl$, make sure it's legal size
  29. 290 rem -------------------------------------------------------
  30. 300 :
  31. 310 print "[197]nter a file name to read, or '*'
  32. 320 [153] [163]10) "to quit: ";
  33. 330 [159]1,0: [132]1,f$: [160]1: [153]
  34. 340 [139] [200](f$,1)[178]"*" [167] [153] "load": [137]980: [143] end program
  35. 350 [139] [195](f$)[179]17 [137]510: [143] length of file name okay
  36. 360 :
  37. 370 [143] --- file name too long, prompt and get a new one
  38. 380 [143] -------------------------------------------------------
  39. 390 :
  40. 400 [153] "(NULL)he file name cannot be longer than
  41. 410 print "   sixteen characters.
  42. 420 [153] "---(NULL)ress any key to continue---
  43. 430 get x$: if x$="" goto430
  44. 440 goto240
  45. 450 :
  46. 460 rem --- prompt for file type
  47. 470 rem ---   if key is s, u, r, or p
  48. 480 rem ---     x=1, 2, 3, or 4
  49. 490 rem ---       for any other key, x=0
  50. 500 :
  51. 510 print "[208]ress [211]/[213]/[210]/[208] for [211][197][209], [213][211][210], [210][197][204], or [208][210][199]"
  52. 520 get x$: if x$="" goto520
  53. 530 x=-(x$="s")-(x$="[211]")-2*(x$="u")-2*(x$="[213]")
  54. 540 x=x-3*(x$="r")-3*(x$="[210]")-4*(x$="p")-4*(x$="[208]")
  55. 550 :
  56. 560 on x gosub1170,1250,1380,1560
  57. 570 if x=0 goto520: rem key was not s, u, r, or p
  58. 580 :
  59. 590 rem --- print prompt for description screens
  60. 600 rem -------------------------------------------
  61. 610 :
  62. 620 if s or p goto690: rem no description screen for seq or prg files
  63. 630 print "---[208]ress any key to continue---
  64. 640 [161] x$: [139] x$[178]"" [137]640
  65. 650 :
  66. 660 [143] --- open files, check for errors
  67. 670 [143] -----------------------------------
  68. 680 :
  69. 690 [159] 15,8,15: [143] open error channel
  70. 700 [141]2010: [143] check for error
  71. 710 [159] 2,8,2,f$: [143] open file for reading
  72. 720 [141]2010: [143] check for error
  73. 730 :
  74. 740 [143] --- if prg, skip to address routine
  75. 750 [143] ---------------------------------------
  76. 760 :
  77. 770 [139] p [167] [141]1700: [137]980: [143] show program address and ending screen
  78. 780 :
  79. 790 [143] --- read file
  80. 800 [143] ----------------------------
  81. 810 [139] [168] p [167] [153] "load(NULL)ress (NULL)left$right$asc(NULL) or (NULL)left$right$asc(NULL)/(NULL)(NULL)len(NULL) to pause---
  82. 820 for x=0 to 1
  83. 830 :   get#2,x$
  84. 840 :   if x$="" then x$=chr$(0)
  85. 850 :   if x$=chr$(13) goto880: rem 'return' is only control code allowed
  86. 860 :   if x$<" " or x$>"[218]" then x$=".": rem throw away control/graphics
  87. 870 :   if x$>"_" and x$<"[193]" then x$=".": rem throw away control/graphics
  88. 880 :   print x$;
  89. 890 :   wait 653,1,255: rem stop only if shift is down
  90. 900 :   x=st: rem if not end-of-file, st=0
  91. 910 next
  92. 920 if r then gosub1940: rem reading rel file
  93. 930 if r goto820: rem more records to read
  94. 940 :
  95. 950 rem --- end program, or re-start if f8 pressed
  96. 960 rem ----------------------------------------------
  97. 970 :
  98. 980 s=0: r=0: p=0: rem reset flags to 'false'
  99. 990 close2: close15: rem close open disk files
  100. 1000 print: print "[208]ress [198]8[146] to restart the program---
  101. 1010 [153] "   (NULL)ress any other key to end
  102. 1020 get x$: if x$="" goto1020
  103. 1030 if x$="[140]" goto240: rem f8  pressed, goto to start
  104. 1040 if case=4 then print chr$(142): rem restore upper/graphics
  105. 1050 print "[147]";: rem clear screen
  106. 1060 end
  107. 1070 :
  108. 1080 rem ****************************
  109. 1090 rem         subroutines
  110. 1100 rem ****************************
  111. 1110 :
  112. 1120 :
  113. 1130 rem ----------------------------
  114. 1140 rem --- read sequential file
  115. 1150 rem ----------------------------
  116. 1160 :
  117. 1170 s=-1: rem set sequential flag 'true'
  118. 1180 f$="0:"+f$+",s,r": rem file name set for sequential read
  119. 1190 return
  120. 1200 :
  121. 1210 rem ----------------------------
  122. 1220 rem --- read user file
  123. 1230 rem ----------------------------
  124. 1240 :
  125. 1250 print "[147][213][211][210], or 'user' files, are sometimes used";
  126. 1260 print "to hold text characters.  [212]hey may also
  127. 1270 [153] "be used to hold binary information.
  128. 1280 print "[212]his program 'filters out' binary data,
  129. 1290 [153] "so you may see only dots when you read
  130. 1300 print "a [213][211][210] file.
  131. 1310 :
  132. 1320 f$[178]"0:"[170]f$[170]",u,r": [143] file name set for user read
  133. 1330 [142]
  134. 1340 :
  135. 1350 [143] ----------------------------
  136. 1360 [143] --- read relative file
  137. 1370 [143] ----------------------------
  138. 1380 [153] "load(NULL)val(NULL), or 'relative' files are special
  139. 1390 print "[195]ommodore data files.  [212]hey contain
  140. 1400 [153] "'records' of data.  valach record is a
  141. 1410 print "fixed length.": print "[217]ou can read records individually if
  142. 1420 [153] "you know the record number, and can
  143. 1430 print "give the necessary commands to the disk
  144. 1440 [153] "drive.": [153]"(NULL)his program does not use the record
  145. 1450 print "number to read the [210][197][204] file.  [201]nstead,
  146. 1460 [153] "the data is displayed in sequence, just
  147. 1470 print "like a [211][197][209] file.
  148. 1480 :
  149. 1490 r[178][171]1: [143] set relative flag 'true'
  150. 1500 f$[178]"0:"[170]f$[170]",r,r": [143] file name set for relative read
  151. 1510 [142]
  152. 1520 :
  153. 1530 [143] ----------------------------
  154. 1540 [143] --- read program file address
  155. 1550 [143] ----------------------------
  156. 1560 [153]"load(NULL)(NULL)chr$ or 'programs' usually contain
  157. 1570 print "characters which are not text.  [201]f they
  158. 1580 [153] "are printed to the screen, they can
  159. 1590 print "cause color changes, graphics, and
  160. 1600 [153] "general havoc.": [153] "ascor that reason, this program only looks";
  161. 1610 [153] "at the first two characters of '(NULL)(NULL)chr$'
  162. 1620 print "files.  [212]hese tell the computer the
  163. 1630 [153] "starting or 'source' address of the
  164. 1640 print "program.
  165. 1650 :
  166. 1660 p[178][171]1: [143] set program flag 'true'
  167. 1670 f$[178]"0:"[170]f$[170]",p,r": [143] file name set for program
  168. 1680 [142]
  169. 1690 :
  170. 1700 [143] -------------------------------------------------------
  171. 1710 [143] --- get program file starting address and display
  172. 1720 [143] -------------------------------------------------------
  173. 1730 [161]#2, a$, b$: [143] first two bytes
  174. 1740 [139] a$[178]"" [167] a$[178][199](0): [143] correct null string bug
  175. 1750 [139] b$[178]"" [167] b$[178][199](0): [143] correct null string bug
  176. 1760 ad[178]256[172]([198](b$))[170][198](a$): [143] address=low byte+(256)*(high byte)
  177. 1770 [153] "(NULL)he starting address of this program
  178. 1780 print "is" ad "in decimal."
  179. 1790 :
  180. 1800 rem *** 2049=(hex 0801), normal start of c64 basic
  181. 1810 if ad=2049 then print "[201]t is probably a [195]64 [194][193][211][201][195] program.": return
  182. 1820 :
  183. 1830 rem *** 7169=(hex 1c01), normal start of c128 basic
  184. 1840 if ad=7169 then print "[201]t is probably a [195]128 [194][193][211][201][195] program.": return
  185. 1850 :
  186. 1860 rem *** if not c64 or c128 basic, default to mach language
  187. 1870 print "[201]t is probably a machine language
  188. 1880 [153] "program."
  189. 1890 [142]
  190. 1900 :
  191. 1910 [143] ----------------------------------------
  192. 1920 [143] --- check for end of relative file
  193. 1930 [143] ----------------------------------------
  194. 1940 [132]15,er: [143] check for 'record not present' error
  195. 1950 [139] er[178]50 [167] r[178]0: [143] 'record not present'
  196. 1960 [142]
  197. 1970 :
  198. 1980 [143] ----------------------------------------
  199. 1990 [143] --- read error channel, stop if error
  200. 2000 [143] ----------------------------------------
  201. 2010 [132]15,er,er$
  202. 2020 [139] er[179]20 [167] [142]
  203. 2030 [153] "loaddisk error---
  204. 2040 print ""er,er$
  205. 2050 if case=4 then print chr$(142)
  206. 2060 print "re-run this program to continue
  207. 2070 [128]
  208.